import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:sessionStorage.getItem("token"),
    user:JSON.parse(sessionStorage.getItem("user")),
    factoryid:sessionStorage.getItem("factoryid"),
    factorystatusid:sessionStorage.getItem("factorystatusid"),
  },
  mutations: {
    // set
    SET_TOKENN: (state, token) => {
      state.token = token
      sessionStorage.setItem("token", token)
    },
    SET_USER: (state, user) => {
      state.user = user
      sessionStorage.setItem("user", JSON.stringify(user))
    },
    SET_FACTORYID: (state, factoryid) => {
      state.factoryid = factoryid
      sessionStorage.setItem("factoryid", factoryid)
    },
    SET_FACTORYSTATUSID: (state, factorystatusid) => {
      state.factorystatusid = factorystatusid
      sessionStorage.setItem("factorystatusid", factorystatusid)
    },
    REMOVE_INFO : (state) => {
      state.token = null
      state.user = null
      sessionStorage.clear();
    }

  },
  actions: {
  },
  modules: {
  }
})
